home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 7_10.lha / 7_10 / p_save.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  1KB  |  35 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <process.h>
  6. include <debug.h>    /* DELETE */
  7. include <stackdir.h>
  8. / Save the current state of this process.
  9. / Returns true when coming back from another process.
  10. nt process::contextswitch()
  11.  
  12.    // Copy the stack out, but first make 
  13.    // certain we're above t_stackbase
  14.    if (debug) /*DELETE*/ cerr << "process" << this << "::contextswitch()\n";
  15.    if (mustrecurse())
  16. return contextswitch();
  17.  
  18.    char *px = Stackdir.plusone();
  19.    t_stacksize = Stackdir.diff(px, t_stackbase);
  20.    if (debug) /*DELETE*/ cerr << "\tt_stacksize <- " << t_stacksize << "\n";
  21.  
  22.    if (t_stack)
  23. delete t_stack;
  24.    t_stack = new char[t_stacksize];
  25.  
  26.    if (Stackdir.grows_up())
  27. memcpy(t_stack, t_stackbase, t_stacksize);
  28.    else
  29. memcpy(t_stack, px, t_stacksize);
  30.  
  31.    int ret = setjmp(t_jb);
  32.    if (debug) /*DELETE*/ cerr << "<<<< process" << this << "::contextswitch() <- " << (ret ? "from longjmp" : "from setjmp") << "\n";
  33.    return ret;
  34.  
  35.